package com.cheung.leetcode.contest.week.week433;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.contest.week.week433
 * @Author :  cheungming
 * @CreateTime : 2025-01-25 11:15:13
 * @Description : 3427
 * @Version : 1.0
 */
public class Code3427Test {

    public int subarraySum(int[] nums) {
        int sum = 0;
        if (nums.length == 0) {
            return sum;
        }
        // nums[i]都是正整数
        for (int i = 0; i < nums.length; i++) {
            int start = StrictMath.max(0, i - nums[i]);
            for (int j = i; j >= start; j--) {
                sum += nums[j];
            }
        }
        return sum;
    }


    @Test
    public void test1() {
        assert subarraySum(new int[]{2, 3, 1}) == 11;
    }

    @Test
    public void test2() {
        assert subarraySum(new int[]{3, 1, 1, 2}) == 13;
    }
}
